import json
import requests
import sys


class IndexChecker():
    def __init__(self):
        self.INDEX_ROOT_URL = "http://localhost:9600/"
        self.QUERY_PAYLOAD = '{"query":{"match_all":true}}'

    def get_index_item_count(self, index_name):
        response = requests.post(self.INDEX_ROOT_URL + index_name + "/csdn/_count", data=self.QUERY_PAYLOAD)
        if response.status_code == 200:
            response_json = json.loads(response.text)
            return response_json['totalHits']
        else:
            return 0

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print 0
    else:
        checker = IndexChecker()
        print checker.get_index_item_count(sys.argv[1])